/**
 * Created by dukes on 2015/11/4.
 */
class SearchPanel extends eui.Component{
    public callObj:any=null;
    public okBack:Function=null;
    public cancelBack:Function=null;
    public constructor(){
        super();
        this.skinName = "pet.SearchPanelearSkin";
    }
    private img_close:eui.Image;
    private name_input:eui.TextInput;
    private img_search:eui.Image;
    private group_id:eui.BitmapLabel;
    public partAdded(name:string, instance:any) {
        super.partAdded(name, instance);
        if (name == "img_close") {
            this.img_close = instance;
            this.img_close.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onClose, this);
        } else if (name == "name_input") {
            this.name_input = instance;
        }else  if( name == "img_search"){
            this.img_search = instance;
            this.img_search.addEventListener(egret.TouchEvent.TOUCH_TAP, this.onOk, this);
        }else if( name == "group_id"){
            this.group_id = instance;
            this.group_id.text = Model.me.id+"";
        }
    }

    private onClose(evt:egret.TouchEvent){
        SoundMgr.getInstance().playEffect(SoundMgr.BTN);
        DisplayController.instance().removeFromAlert(GameConst.GrayMask);
        DisplayController.instance().removeFromAlert(this);
    }

    private onOk(evt:egret.TouchEvent){
        DisplayController.instance().removeFromAlert(GameConst.GrayMask);
        DisplayController.instance().removeFromAlert(this);
        var id = parseInt(this.name_input.text);
        if( id ){
            window["__visit"](id,true);
        }
        else
            ShowHint("请输入要查找的ID");
    }

    public show(){
        DisplayController.instance().addToAlert(GameConst.GrayMask);
        DisplayController.instance().addToAlert(this);
        //if( this.group_id.text == ""){
        //    GetUIAssetsNum(Model.me.id,this.group_id);
        //}
    }

    public measure(){
        super.measure();
        this.x = GameConst.StageW - this.measuredWidth >> 1;
        this.y = GameConst.StageH - this.measuredHeight >> 1;
    }

    private static _instance:SearchPanel;
    public static getInstance():SearchPanel{
        if( SearchPanel._instance == null )
            SearchPanel._instance = new SearchPanel();
        return SearchPanel._instance;
    }
}